package com.tusuo.stds.rest;

import android.text.TextUtils;


import com.tusuo.stds.util.DateUtils;

import org.parceler.Parcel;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author J.Huang
 * @version 1.0
 *
 */

public class LevelRecordList extends ApiResult {
    public int Total;
    public List<LevelRecord> Data;

    @Parcel
    static public class LevelRecord {

        public static final String EXTRA_NAME = LevelRecord.class.getName();

        public int Id;
        public int LevelId;
        public String Title;
        public String Description;
        public float CorrectRate;
        public String CreateTime;
        public int ClearanceTime;   // 单位：s
        public int CompletionStatus;

        public String getFormattedCreateTime() {
            if (!TextUtils.isEmpty(CreateTime)) {
                try {
                    Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm").parse(CreateTime);


                    if (DateUtils.isToday(date)) {
                        return new SimpleDateFormat("HH:mm").format(date);
                    } else if (DateUtils.isYesterday(date)) {
                        return "昨天 " + new SimpleDateFormat("HH:mm").format(date);
                    } else if (DateUtils.isThisYear(date)) {
                        return new SimpleDateFormat("MM/dd HH:mm").format(date);
                    } else {
                        return CreateTime;
                    }

                } catch (ParseException e) {
                    e.printStackTrace();
                    return CreateTime;
                }
            }
            return "";
        }

        @Override
        public String toString() {
            return "LevelRecord{" +
                    "Id=" + Id +
                    ", LevelId=" + LevelId +
                    ", Title='" + Title + '\'' +
                    ", Description='" + Description + '\'' +
                    ", CorrectRate=" + CorrectRate +
                    ", CreateTime=" + CreateTime +
                    ", ClearanceTime=" + ClearanceTime +
                    ", CompletionStatus=" + CompletionStatus +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "SchoolList{" +
                "Total=" + Total +
                ", Data=" + Data +
                '}';
    }
}
